package com.breeze.components.log.converter;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import com.breeze.components.core.util.web.RequestContextUtil;

/**
 * @author breeze
 */
public class UrlPatternConverter extends ClassicConverter {

  public static String figure(ILoggingEvent iLoggingEvent) {

    try {
      Class.forName("org.springframework.web.context.request.RequestContextHolder");
      return RequestContextUtil.getRequestUrl();
    } catch (Exception ignored) {
      // ignore
    }
    return RequestContextUtil.UNKNOWN_URL;
  }

  @Override
  public String convert(ILoggingEvent le) {
    return figure(le);
  }
}
